<template>
	<view class="">
		<navbar :title="i18n.yzzjc"></navbar>
		<view class="w690 auto">
			<view class="f14 color-white lhl175k mt20">{{ i18n.yztips }}</view>
		</view>
		<view class="bgcc auto border mx25 px15 py15 h294 w636 mt30 flex wrapyes">
			<text v-for="(item, index) in GroupArray" :key="index" class="white mr8">{{ item }}</text>
		</view>
		<view class="box w690 auto fsb wrapyes text--center white my15">
			<text class="block wp31 bor5 py9 my5 bg-theme" v-for="(item, index) in menuArray" :key="index" @click="Choice(index)" :class=" GroupArray.indexOf(item) > -1?'opacity03':''">
				{{ item }}
			</text>
		</view>
		<view class="btn-blue block auto mt15 w690" @click="ToHome()">下一步</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			menuArray: ['remind', 'frewg', 'rqrqw', 'hojiijop', 'vwevdf', 'grgtrh', 'btrysh', 'vrebrn', 'Fwefe', 'Fwefes', 'toggle', 'toggles'],
			GroupArray: [],
			NumArray: [],
			otoken: ''
		};
	},
	computed: {
		i18n() {
			return this.$t('login');
		}
	},
	onLoad(option) {
		this.remark = option.Memo;
		this.menuArray = option.Memo.split(',').sort(() => Math.random() - 0.5);
	},
	onShow() {
		this.otoken = uni.getStorageSync('token');
	},
	methods: {
		ToHome() {
			if (this.GroupArray.length != 12) {
				uni.showToast({
					title: this.$t('tips').qxtips,
					icon: 'none'
				});
				return false;
			}
			this.getLogin();
		},
		Choice(index) {
			var values = this.menuArray[index];
			this.NumArray.push(index);
			if (this.GroupArray.indexOf(values) > -1) {
				var num = this.GroupArray.indexOf(values);
				this.GroupArray.splice(num, 1);
			} else {
				this.NumArray.push(index);
				this.GroupArray.push(this.menuArray[index]);
			}
		},
		async getLogin() {
			let params = {
				memo: this.GroupArray.join(',')
			};
			let { data } = await this.$http.post('login.register', params, { isAuth: false, tipConfig: { isLoading: false } });
			uni.setStorageSync('token', data.token);
			uni.switchTab({
				url: '../index/index'
			});
			if (this.token) {
				uni.reLaunch({
					url: '../my/account'
				});
			} else {
				uni.setStorageSync('token', data.token);
				uni.switchTab({
					url: '../index/index'
				});
			}
		},
	}
};
</script>

<style lang="less">
.h294 {
	min-height: 234rpx;
	line-height: 88rpx;
}
.border {
	border: 1rpx solid rgba(151, 151, 151, 0.6);
	border-radius: 4rpx;
}
</style>
